package com.zbest.zpay.gw.dal.dao;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;

import com.zbest.common.lang.enums.BizCode;
import com.zbest.common.lang.exception.ZpayException;
import com.zbest.zpay.gw.dal.mapper.GwTransactionContentMapper;
import com.zbest.zpay.gw.dal.model.GwTransactionContentDO;

/**
 * Created by wenfeihu on 16/5/20.
 */
@Service("gwTransactionContentDAO")
public class GwTransactionContentDAO {

    @Resource
    private GwTransactionContentMapper gwTransactionContentMapper;

    public void insert(GwTransactionContentDO gwTransactionContentDO) {

        try {
            gwTransactionContentMapper.insert(gwTransactionContentDO);
        } catch (DataIntegrityViolationException e) {
            throw new ZpayException(BizCode.DUPLICATED_ERROR);
        }
    }

    public void update(String serialNo, String responseContent) {

        int row = gwTransactionContentMapper.update(serialNo, responseContent, new Date());
        if (row <= 0) {
            throw new ZpayException(BizCode.DATA_NOT_EXISTS);
        }
    }

}
